package demo7;

// 状态
public class Test14 {
    public static void main(String[] args) {
        Thread t=new Thread(()->{

            while(!Thread.currentThread().isInterrupted()){
                System.out.println("线程开始");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
                System.out.println("线程结束");
            }

        });
        System.out.println(t.getState());       //  NEW 状态： start调用之前的状态
        t.start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(t.getState());       // Runnable 状态 ： 就绪状态
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t.interrupt();                         // TIMED_WAITING: 由于sleep() 造成的阻塞状态
        System.out.println(t.getState());
    }
}
